#ifndef CH452_H_INCLUDED
#define CH452_H_INCLUDED
#include <avr/io.h>
#include <leaf/base.h>
/* 与ch452的连接定义 */
#if (CH452_CONFIGED <= 0)
#define CH452_PORT		PORTC
#define CH452_DDR		DDRC
#define CH452_DIN		PC0
#define CH452_CLK		PC1
#define CH452_LOAD		PC2
#define CH452_INPUT		_BV(CH452_DIN) | _BV(CH452_CLK) | _BV(CH452_LOAD)
#define CH452_PIN		PINE
#define CH452_DOUT_PORT	PINE
#define CH452_DOUT_DDR	DDRE
#define CH452_DOUT		PE4
#endif

static void inline ch452_port_init( void )
{
	CH452_DDR |= CH452_INPUT;
	CH452_PORT |= CH452_INPUT;
	cbio( CH452_PORT, CH452_LOAD );
	sbio( CH452_DOUT_DDR, CH452_DOUT );
	sbio( CH452_DOUT_PORT, CH452_DOUT );
}
static inline void ch452_init( void )
{
	ch452_port_init();
}

void ch452_write( uint16_t data );
uint16_t ch452_read( uint8_t bits );

static inline uint8_t ch452_readkey( void )
{
	return (uint8_t)ch452_read( 6 );
}

#endif /* CH452_H_INCLUDED */
